package com.sunway.paisong.pos.ui;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.sunway.paisong.pos.R;

public class MainActivity extends BaseActivity {

	private static MainActivity instance = null;

	private TextView tvStaffNumValue;
	private TextView tvStaffNameValue;
	private TextView tvStaffPhoneValue;
	private TextView tvStaffVPhoneValue;
	private Button btnBind;
	private boolean isBind = false;
	private String staffNum;
	private String staffName;
	private String staffPhone;
	private String staffVPhone;
	private SharedPreferences sp;

	public static MainActivity getInstance() {
		return instance;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		instance = this;
		setContentView(R.layout.activity_main);

		initDate();
		intiView();
	}

	/**
	 * 初始化View
	 */
	private void intiView() {
		tvStaffNumValue = (TextView) findViewById(R.id.tv_staff_num_value);
		tvStaffNameValue = (TextView) findViewById(R.id.tv_staff_name_value);
		tvStaffPhoneValue = (TextView) findViewById(R.id.tv_staff_phone_value);
		tvStaffVPhoneValue = (TextView) findViewById(R.id.tv_staff_v_phone_value);
		btnBind = (Button) findViewById(R.id.btn_bind);
		if (isBind) {
			tvStaffNumValue.setText(staffNum);
			tvStaffNameValue.setText(staffName);
			tvStaffPhoneValue.setText(staffPhone);
			tvStaffVPhoneValue.setText(staffVPhone);
			btnBind.setText("重新绑定个人信息");
		} else {
			btnBind.setText("绑定个人信息");
		}
		btnBind.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent it = new Intent(MainActivity.this, EditUserActivity.class);
				startActivity(it);
			}
		});
	}

	/**
	 * 初始化数据
	 */
	private void initDate() {
		sp = getSharedPreferences("com.sunway.paisong.pos.sp", MODE_PRIVATE);
		isBind = sp.getBoolean("is_bind", false);
		if (isBind) {
			staffNum = sp.getString("staff_num", "");
			staffName = sp.getString("staff_name", "");
			staffPhone = sp.getString("staff_phone", "");
			staffVPhone = sp.getString("staff_v_phone", "");
		}
	}

	public void refreshForm() {
		initDate();
		intiView();
	}

}
